<?php
// +----------------------------------------------------------------------
// | Ghome/Home/Event/ZCEEvent
// +----------------------------------------------------------------------
// | Author: alex <gt199899@gmail.com>
// +----------------------------------------------------------------------
// | Version: 2014-04-08
// +----------------------------------------------------------------------
// | Copyright: Perfect Is Shit
// +----------------------------------------------------------------------
namespace Home\Event;
class ZCEEvent{

	public function __construct(){}

	/**
	 * zce编辑保存条目内容
	 * @access public
	 * @author alex
	 * @version 20140410
	 * @copyright Perfect Is Shit
	 */
	public function editSave(){
		if(!IS_AJAX){
			E('request is not ajax');
		}
		$content = I('post.c');
		$content = htmlspecialchars_decode($content, ENT_QUOTES);
		$file = I('post.f', '', 'base64_decode');
		$controller = A('ZCE', 'controller');
		$controller->_initialize();
		$file = $controller->zceTextPath . "/" . $file . ".inc";
		if(file_exists($file)){
			unlink($file);
		}
		if(!is_dir(dirname($file))){
			mkdir(dirname($file), 0777, true);
		}
		$fhandle = @fopen($file, 'ab+');
		$write_result = @fwrite($fhandle, $content);
		@fclose($fhandle);
		if($fhandle === false || $write_result == false){
			//Think\Log::write("{$file} can not create or can not write",'WARN');
			return false;
		}
		return true;
	}

}